package com.hsjk.szwj.module.official.service.video;

import cn.hutool.core.util.ObjectUtil;
import com.hsjk.szwj.framework.common.exception.ServiceException;
import com.hsjk.szwj.framework.common.exception.enums.GlobalErrorCodeConstants;
import com.hsjk.szwj.framework.common.pojo.PageResult;
import com.hsjk.szwj.module.official.controller.admin.video.vo.AdminOfficialWebsiteVideoCreateReqVO;
import com.hsjk.szwj.module.official.controller.admin.video.vo.AdminOfficialWebsiteVideoPageReqVO;
import com.hsjk.szwj.module.official.controller.admin.video.vo.AdminOfficialWebsiteVideoUpdateReqVO;
import com.hsjk.szwj.module.official.controller.app.video.vo.AppOfficialWebsiteVideoListReqVO;
import com.hsjk.szwj.module.official.conver.video.OfficialWebsiteVideoConvert;
import com.hsjk.szwj.module.official.dal.dataobject.video.OfficialWebsiteVideoDO;
import com.hsjk.szwj.module.official.dal.mysql.video.IOfficialWebsiteVideoMapper;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Service;
import org.springframework.validation.annotation.Validated;

import javax.annotation.Resource;
import java.util.List;

/**
 * @author chenjiawei
 * @desc
 * @Date 2023/07/31 22:41
 **/
@Service
@Validated
@Slf4j
public class OfficialWebsiteVideoServiceImpl implements IOfficialWebsiteVideoService {

    @Resource
    private IOfficialWebsiteVideoMapper officialWebsiteVideoMapper;

    @Override
    public List<OfficialWebsiteVideoDO> getOfficialWebsiteVideoList(AppOfficialWebsiteVideoListReqVO reqVO) {
        return officialWebsiteVideoMapper.selectList(reqVO);
    }

    @Override
    public Long createOfficialWebsiteVideo(AdminOfficialWebsiteVideoCreateReqVO reqVO) {
        OfficialWebsiteVideoDO officialWebsiteVideoDO =
                OfficialWebsiteVideoConvert.INSTANCE.convertOfficialWebsiteVideoDO(reqVO);
        officialWebsiteVideoMapper.insert(officialWebsiteVideoDO);
        return officialWebsiteVideoDO.getId();
    }

    @Override
    public void updateOfficialWebsiteVideo(AdminOfficialWebsiteVideoUpdateReqVO reqVO) {
        OfficialWebsiteVideoDO officialWebsiteVideoDO =
                OfficialWebsiteVideoConvert.INSTANCE.convertOfficialWebsiteVideoDO(reqVO);
        officialWebsiteVideoMapper.updateById(officialWebsiteVideoDO);
    }

    @Override
    public void deleteOfficialWebsite(Long id) {
        if (ObjectUtil.isNull(id)) {
            throw new ServiceException(GlobalErrorCodeConstants.BAD_REQUEST.getCode()
                    , "id不能为空");
        }
        officialWebsiteVideoMapper.deleteById(id);
    }

    @Override
    public PageResult<OfficialWebsiteVideoDO> getOfficialWebsiteVideoPage(AdminOfficialWebsiteVideoPageReqVO reqVO) {
        return officialWebsiteVideoMapper.selectPage(reqVO);
    }
}
